{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>{if !empty($data)}修改{else}添加{/if}段位</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="form_basic.html#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal" name="add_cate" id="add_grad" method="post" action="">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">名称：</label>
                            <div class="input-group col-sm-4">
                                <input id="name" type="text" class="form-control" name="name" value="{$data.name|default=''}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">段位头像：</label>
                            <div class="controls uploadrow2" data-max="1" title="点击修改图片" rel="p_cover">
                                <input type="hidden" name="user_grad_logo" id="cover_id_p_cover"
                                       value="{$data.user_grad_logo|default=''}" data-callback="uploadImgCallback"
                                       value=""/>
                                <div class="upload-img-box" rel="img" {if empty($data[
                                'user_grad_logo'])} style="display:none" {/if} >
                                <div class="upload-pre-item2">
                                    <img width="100" height="100" src="{$data.user_grad_logo|default=''}"/>
                                </div>
                                <em class="edit_img_icon">&nbsp;</em>
                               </div>
                            </div>
                        </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">段位图标：</label>
                                <div class="controls uploadrow2" data-max="1" title="点击修改图片" rel="p_cover2">
                                    <input type="hidden" name="grad_logo" id="cover_id_p_cover2"
                                           value="{$data.grad_logo|default=''}" data-callback="uploadCallback" value=""/>
                                    <div class="upload-img-box" rel="img" {if empty($data[
                                    'grad_logo'])} style="display:none" {/if} >
                                    <div class="upload-pre-item2">
                                        <img width="100" height="100" src="{$data.grad_logo|default=''}"/>
                                    </div>
                                    <em class="edit_img_icon">&nbsp;</em>
                                </div>
                            </div>
                            </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">过关获取金币：</label>
                            <div class="input-group col-sm-4">
                                <input id="orderby" type="text" class="form-control" name="reward_point" value="{$data.reward_point|default=''}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">参赛消费金币：</label>
                            <div class="input-group col-sm-4">
                                <input id="orderby" type="text" class="form-control" name="consume_point" value="{$data.consume_point|default=''}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">段位过关星数：</label>
                            <div class="input-group col-sm-4">
                                <input id="orderby" type="text" class="form-control" name="pass_stars" value="{$data.pass_stars|default=''}">
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">段位奖励宝箱类型：</label>
                            <div class="col-sm-4 m-l-n">
                                <select class="form-control" name="box_id" id="box">
                                    <option  value="">请选择</option>
                                    {foreach name="box" item="vo" key="k"} 
                                        <option {if condition="@$data.box_id eq $vo.id"}selected{/if} value="{$vo.id}">{$vo.name|default=''}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">段位奖励宝箱数：</label>
                            <div class="input-group col-sm-4">
                                <input id="orderby" type="text" class="form-control" name="reward_box" value="{$data.reward_box|default=''}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">挑战成功获取经验：</label>
                            <div class="input-group col-sm-4">
                                <input id="orderby" type="text" class="form-control" name="pass_exp" value="{$data.pass_exp|default=''}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">平局获取经验：</label>
                            <div class="input-group col-sm-4">
                                <input id="orderby" type="text" class="form-control" name="drawn_exp" value="{$data.drawn_exp|default=''}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">挑战失败获取经验：</label>
                            <div class="input-group col-sm-4">
                                <input id="orderby" type="text" class="form-control" name="pass_fail_exp" value="{$data.pass_fail_exp|default=''}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">本段位分享奖励金币值：</label>
                            <div class="input-group col-sm-4">
                                <input id="orderby" type="text" class="form-control" name="share_reward" value="{$data.share_reward|default=''}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">获取经验倍数：</label>
                            <div class="input-group col-sm-4">
                                <input id="orderby" type="text" class="form-control" name="exp_multiple" value="{$data.exp_multiple|default=''}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">段位排序：</label>
                            <div class="input-group col-sm-4">
                                <input id="orderby" type="text" class="form-control" name="sort" value="{$data.sort|default=''}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
{include file="public/footer" /}

<script type="text/javascript">

$(function(){
    
    //初始化上传图片插件
    initUploadImg();
});


function uploadImgCallback(name,id,src){

    $('#cover_id_p_cover').val(src);
}
function uploadCallback(name,id,src){
    console.log(src)
    $('#cover_id_p_cover2').val(src);
}

//切换按钮
$('input[type="checkbox"][name=status]').change(function() {
    $('input[name=status]').val($(this).get(0).checked ? 1: 0);
});
</script>

<script type="text/javascript">

    $(function(){
        $('#add_grad').ajaxForm({
            beforeSubmit: checkForm, 
            success: complete, 
            dataType: 'json'
        });
        
        function checkForm(){
            if( '' == $.trim($('#name').val())){
                layer.msg('请输入名称',{icon:2,time:1500,shade: 0.1}, function(index){
                layer.close(index);
                });
                return false;
            }
            if( '' == $.trim($('#cover_id_p_cover').val())){
                layer.msg('请添加图片',{icon:2,time:1500,shade: 0.1}, function(index){
                layer.close(index);
                });
                return false;
            }
             if( '' == $.trim($('#box').val())){
                layer.msg('请添加宝箱类型',{icon:2,time:1500,shade: 0.1}, function(index){
                layer.close(index);
                });
                return false;
            }
        }

        function complete(data){
            if(data.code==1){
                layer.msg(data.msg, {icon: 6,time:1500,shade: 0.1}, function(index){
                    window.location.href="{:url('grad/index')}";
                });
            }else{
                layer.msg(data.msg, {icon: 5,time:1500,shade: 0.1});
                return false;   
            }
        }
     
    });

    //IOS开关样式配置
   var elem = document.querySelector('.js-switch');
        var switchery = new Switchery(elem, {
            color: '#1AB394'
        });
    var config = {
        '.chosen-select': {},                    
    }
    for (var selector in config) {
        $(selector).chosen(config[selector]);
    }

</script>
</body>
</html>